<?php
	class Home extends MY_Controller{
		
		public function __construct(){
			parent::__construct();		
			$this->load->model('fund_model');
			$this->load->model('kiosk_model');
			
		}
		
		public function index(){
		
			// Get total kiosk
			$data['total_kiosk'] 	= $this->kiosk_model->get_total_kiosk();
			
			// Get Top 5 kiosk device
			$data['top5'] 			= $this->fund_model->get_top_5_kiosk();
			
			// Get 5 latest kiosk have inserted donate
			$data['latest_donate']	= $this->fund_model->get_latest_kiosk_donate();	

			/* Array Examples for draw column chart 
			$arr = array(
				array('Year', 'Sales', 'Expenses'),
				array('2004',  9000, 5200),
				array('2005',  8170, 460)
			);	*/
			
			$arr = array();
			$arr_title = array('KIOSK','Donate');
			array_push($arr, $arr_title);
			
			foreach($data['top5'] as $v){
				//echo $v['id'].",". $v['total_donate'];
				$arr_donate = array($v['name'], intval($v['total_donate']));
				array_push($arr, $arr_donate);
			}
			
			//echo json_encode($arr);
				
			$data['chart']	 = json_encode($arr);
				
			$data['title'] = "Welcome";
			
			$this->load->view('templates/header1', $data);
			$this->load->view('home/index', $data);
			$this->load->view('templates/right', $data);
			$this->load->view('templates/footer');
			
		}		
	}
?>